<?php
/*
	本插件：$this->model('model')->方法名();
	其他地方调用：model('jy_txfaceid/model')->方法名();
*/
namespace jy_txfaceid;
defined('BY_JYA') or exit('error');
require_once ROOT_PLUGIN.'jy_txfaceid/vendor/autoload.php';
use \TencentCloud\Common\Credential;
use \TencentCloud\Common\Profile\ClientProfile;
use \TencentCloud\Common\Profile\HttpProfile;
use \TencentCloud\Common\Exception\TencentCloudSDKException;
use \TencentCloud\Faceid\V20180301\FaceidClient;
use \TencentCloud\Faceid\V20180301\Models\IdCardVerificationRequest;
class api extends \plugin{
	public function checkinfo($params=array()){
		$setting=plugin('jy_txfaceid')->plugin_setting('basic');
		if(!$setting['secretid'] || !$setting['secretkey']){
			exi('请联系管理员，设置基本参数！','error');
		}
        // 实例化一个认证对象，入参需要传入腾讯云账户secretId，secretKey,此处还需注意密钥对的保密
		// 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
		$cred = new Credential($setting['secretid'], $setting['secretkey']);
		// 实例化一个http选项，可选的，没有特殊需求可以跳过
		$httpProfile = new HttpProfile();
		$httpProfile->setEndpoint("faceid.tencentcloudapi.com");

		// 实例化一个client选项，可选的，没有特殊需求可以跳过
		$clientProfile = new ClientProfile();
		$clientProfile->setHttpProfile($httpProfile);
		// 实例化要请求产品的client对象,clientProfile是可选的
		$client = new FaceidClient($cred, "", $clientProfile);

		// 实例化一个请求对象,每个接口都会对应一个request对象
		$req = new IdCardVerificationRequest();
		$params = array(
			"IdCard" => $checkinfo['cardnum'],
			"Name" => $checkinfo['realname'],
		);
		$req->fromJsonString(json_encode($params));
		// 返回的resp是一个IdCardVerificationResponse的实例，与请求对象对应
		$resp = $client->IdCardVerification($req);

		// 输出json格式的字符串回包
		$data=$resp->toJsonString();
		$data=json_decode($data,true);
		if($data['Response']['Result']){
			exi('身份核实失败：'.$data['Response']['Description'],'error');
		}
        return $data;
    }
}
?>